# -*- coding: utf-8 -*-
# created on 2016/9/28

from mathsolver.functions.base import *
from sympy import Abs


# 圆上的点到直线的距离的最值问题
class YuanToLineRange(BaseFunction):
    """
    圆x^{2}+y^{2}-2y=3上的点到直线x-y-5=0的距离的最大值是()
    """
    def solver(self, *args):
        dian_to_line_juli = args[0].sympify()
        banjing = args[1].sympify()
        if isinstance(args[2], str):
            text = args[2]
            text = str(text)
        else:
            text = args[2]
        if '最大' in text:
            juli_max = dian_to_line_juli + banjing
            self.steps.append(["", "距离最大值为%s" % (new_latex(juli_max))])
            self.output.append(BaseNumber(juli_max))
        elif ('最小' in text) or ('最短' in text):
            juli_min = dian_to_line_juli - banjing
            self.steps.append(["", "距离最小值为%s" % (new_latex(juli_min))])
            self.output.append(BaseNumber(juli_min))
        self.label.add("圆上的点到直线的距离的最值问题")
        return self


# 圆上点到定点的距离的最值问题
class YuanToPointRange(BaseFunction):
    def solver(self, *args):
        yuanxin_todian_juli = args[0].sympify()
        banjing = args[1].sympify()
        text = args[2]
        if "最大" in text:
            juli_max = yuanxin_todian_juli + banjing
            self.steps.append(["", "距离最大值为%s" % (new_latex(juli_max))])
            self.output.append(BaseNumber(juli_max))
        elif "最小" in text:
            juli_min = Abs(yuanxin_todian_juli - banjing)
            self.steps.append(["", "距离最小值为%s" % (new_latex(juli_min))])
            self.output.append(BaseNumber(juli_min))
        self.label.add("圆上点到定点的距离的最值问题")
        return self


# 两圆上两动点间的距离的最值
class YuanAndYuanRange(BaseFunction):
    def solver(self, *args):
        yuanxin_to_yuanxin_juli = args[0].sympify()
        banjing1 = args[1].sympify()
        banjing2 = args[2].sympify()
        guanxi = args[3].sympify()
        if isinstance(args[4], str):
            text = args[2].value
            text = str(text)
        else:
            text = args[4]
        if guanxi == 1:
            juli_max = yuanxin_to_yuanxin_juli + banjing1 + banjing2
            juli_min = yuanxin_to_yuanxin_juli - banjing1 - banjing2
        elif guanxi == 2:
            juli_max = yuanxin_to_yuanxin_juli + banjing1 + banjing2
            juli_min = yuanxin_to_yuanxin_juli - banjing1 - banjing2
        elif guanxi == 3:
            juli_max = yuanxin_to_yuanxin_juli + banjing1 + banjing2
            juli_min = 0
        elif guanxi == 4:
            juli_max = yuanxin_to_yuanxin_juli + banjing1 + banjing2
            juli_min = 0
        elif guanxi == 5:
            juli_max = yuanxin_to_yuanxin_juli + banjing1 + banjing2
            juli_min = Abs(banjing1 - banjing2) - yuanxin_to_yuanxin_juli
        if '最大' in text:
            self.steps.append(["", "距离最大值为%s" % (new_latex(juli_max))])
            self.output.append(BaseNumber(juli_max))
        elif ('最小' in text) or ('最短' in text):
            self.steps.append(["", "距离最小值为%s" % (new_latex(juli_min))])
            self.output.append(BaseNumber(juli_min))
        elif '最值' in text:
            self.steps.append(["", "距离最大值为%s, 距离最小值为%s" % (new_latex(juli_max), new_latex(juli_min))])
            self.output.append(BaseValues([juli_max, juli_min]))
        self.label.add("两圆上两动点间的距离的最值")
        return self
